# -*- coding: utf-8 -*-
from order.models import Dish_cart
import urllib
import urllib2
def send_sms(smsMob, smsText):
    error_msg = {"-1":"没有该用户账户",
           "-2":"密钥不正确（不是用户密码）",
           "-3":"短信数量不足",
           "-11":"该用户被禁用",
           "-14":"短信内容出现非法字符",
           "-41":"手机号码为空",
           "-42":"短信内容为空",
           }
    url= 'http://utf8.sms.webchinese.cn/'
    values = {'Uid' : 'edian',
          'Key' : 'ediancfordgieieindongguang',
          'smsMob' : smsMob, 
          'smsText' : smsText }
    data = urllib.urlencode(values)
    req = urllib2.Request(url, data)
    response = urllib2.urlopen(req)
    the_page = response.read()
    print the_page
    
class MyCartMiddleware(object):
    def process_request(self, request):
        user = request.user
        session_key = request.session.session_key
        if user.is_authenticated():
            dc = Dish_cart.objects.filter(user__pk=user.id, state=False)
        else:
            dc = Dish_cart.objects.filter(session__pk=session_key, state=False)
        request.carts = dc
        
if __name__ == '__main__':
    send_sms('13712335858','请不要回复')

